package biz.datalk.industrialland.admin.modules.online.config.hook;

import biz.datalk.industrialland.admin.modules.online.config.cfg.enums.SqlOperationTypeEnum;
import biz.datalk.industrialland.admin.modules.online.dynform.pojo.dto.DynformAutoDTO;
import biz.datalk.industrialland.admin.modules.online.dynform.pojo.dto.DynformFieldDTO;
import biz.datalk.industrialland.admin.modules.online.dynform.pojo.dto.DynformHeadDTO;
import biz.datalk.industrialland.admin.modules.online.dynform.pojo.po.DynformHead;
import biz.datalk.industrialland.common.result.UnifyResult;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 动态表单钩子接口
 *
 * @author tarofang@163.com
 * @date 2019-12-30
 */
public interface IDynfromHook {
    void beforeList(DynformAutoDTO dynformAutoDTO);

    UnifyResult afterList(DynformAutoDTO dynformAutoDTO, UnifyResult result);

    void beforeDetail(DynformAutoDTO dynformAutoDTO);

    UnifyResult afterDetail(DynformAutoDTO dynformAutoDTO, UnifyResult result);

    void beforeInsert(DynformAutoDTO dynformAutoDTO);

    UnifyResult afterInsert(DynformAutoDTO dynformAutoDTO, UnifyResult result);

    void beforeUpdate(DynformAutoDTO dynformAutoDTO);

    UnifyResult afterUpdate(DynformAutoDTO dynformAutoDTO, UnifyResult result);

    void beforeDelete(DynformAutoDTO dynformAutoDTO);

    UnifyResult afterDelete(DynformAutoDTO dynformAutoDTO, UnifyResult result);

    HookSplicingResult splicingListRowSql(DynformHead tableInfo, Map<String, String> queryMap, DynformAutoDTO dynformAutoDTO, List<DynformFieldDTO> fields);
    HookSplicingResult splicingListTotalSql(DynformHead tableInfo, Map<String, String> queryMap, DynformAutoDTO dynformAutoDTO, List<DynformFieldDTO> fields);
    HookSplicingResult splicingDetailSql(DynformHead tableInfo, DynformAutoDTO dynformAutoDTO, List<DynformFieldDTO> fields);
    HookSplicingResult splicingInsertSql(DynformHead tableInfo, DynformAutoDTO dynformAutoDTO, List<DynformFieldDTO> fields, HookValidParamsResult validParamsResult);
    HookSplicingResult splicingUpdateSql(DynformHead tableInfo, DynformAutoDTO dynformAutoDTO, List<DynformFieldDTO> fields, HookValidParamsResult validParamsResult);
    HookSplicingResult splicingDeleteSql(DynformHead tableInfo, DynformAutoDTO dynformAutoDTO, List<DynformFieldDTO> fields);

    /**
     * 执行 SQL 语句
     *
     * @author tarofang@163.com
     * @date 2019年12月30日
     *
     */
    Object execSql(String sql, List<Object> args, SqlOperationTypeEnum sqlOperationTypeEnum);

    /**
     * 解析查询参数 并给查询参数赋值
     *
     * @author tarofang@163.com
     * @date 2019年12月30日
     *
     * @param dynformAutoDTO 前端 提交的数据
     * @param table 当前表信息
     * @param allFields 当前表的所有字段
     * @return 查询参数
     */
    Map<String, String> parseQueryParams(DynformAutoDTO dynformAutoDTO, HttpServletRequest request, DynformHead table, List<DynformFieldDTO> allFields, SqlOperationTypeEnum sqlOperationTypeEnum);

    Map<String, String> parseParams(DynformAutoDTO dynformAutoDTO, HttpServletRequest request, DynformHead table, List<DynformFieldDTO> allFields, SqlOperationTypeEnum sqlOperationTypeEnum);

    HookValidParamsResult validParams(DynformAutoDTO dynformAutoDTO, DynformHead table, List<DynformFieldDTO> existsFields, Map<String, String> paramsMap, SqlOperationTypeEnum sqlOperationTypeEnum);

    void beforeDoButton(DynformAutoDTO dynformAutoDTO);
    UnifyResult doButton(DynformHeadDTO tableDTO, String btnCode, Map<String, String> paramsMap);
    UnifyResult afterDoButton(DynformAutoDTO dynformAutoDTO, UnifyResult result);

    UnifyResult saveDBSuccess(Integer opResInt, DynformAutoDTO dynformAutoDTO, DynformHead table, List<DynformFieldDTO> existsFields, Map<String, String> paramsMap, SqlOperationTypeEnum sqlOperationTypeEnum);
    HookValidParamsResult beforeExecSQL(HookValidParamsResult validParamsResult, DynformAutoDTO dynformAutoDTO, DynformHead table, List<DynformFieldDTO> fieldList, Map<String, String> paramsMap, SqlOperationTypeEnum sqlOperationTypeEnum);
}
